home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / plain C OS8 / AMReminder / Add.c next >
Encoding:
C/C++ Source or Header  |  1998-10-29  |  4.9 KB  |  194 lines  |  [TEXT/CWIE]

  1. /* Add.c -- Modal dialog */
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <TextEdit.h>
  11. #include <Appearance.h>
  12. #include <stdlib.h>
  13.  
  14. #include "ResourceDefs.h"
  15. #include "Miscellany.h"
  16. #include "ControlUtils.h"
  17.  
  18. #include "Dispatcher.h"
  19. #include "Add.h"
  20.  
  21. #define kOKButton        1
  22. #define kCancelButton        2
  23. #define kLogoImage        3
  24. #define kAddReminderForLabel        4
  25. #define kDateLabel        5
  26. #define kDate2Field        6
  27. #define kTimeLabel        7
  28. #define kTime2Field        8
  29. #define kMessageLabel        9
  30. #define kMessage2Field        10
  31. #define kWhenRemindingLabel        11
  32. #define kDisplayIconCheck        12
  33. #define kDisplayAlertCheck        13
  34. #define kPlaySoundCheck        14
  35. #define kSoundPopupPopup        15
  36.  
  37.  
  38. /*----------*/
  39. Boolean        GetAdd (
  40.     DReminder*        ioData)
  41. {
  42.     Boolean            result = false;
  43.     Add*        dialog = NewAdd ();
  44.  
  45.     result = AMDialog_RunModal ((AMDialog*)dialog, DLOG_Add, (AMSignaler*)ioData);
  46.  
  47.     DeleteAdd (dialog);
  48.  
  49.     return result;
  50. }
  51.  
  52. //----------
  53. Add*        NewAdd ()
  54. {
  55.     Add*        dialog;
  56.  
  57.     dialog = (Add*)malloc (sizeof (Add));
  58.     Add_Init (dialog);
  59.     SetClassID (dialog, classAdd);
  60.  
  61.     return dialog;
  62. }
  63.  
  64. //----------
  65. void    DeleteAdd (
  66.     Add*        dialog)
  67. {
  68.     Add_Free (dialog);
  69.     free (dialog);
  70. }
  71.  
  72. //----------
  73. void    Add_Init (
  74.     Add*        self)
  75. {
  76.     AMDialog_Init ((AMDialog*)self);
  77. }
  78.  
  79. //----------
  80. void    Add_Free (
  81.     Add*        self)
  82. {
  83.     AMDialog_Free ((AMDialog*)self);
  84. }
  85.  
  86. //----------
  87. void    Add_FinishMake (
  88.     Add*        self)
  89. {
  90.     self->mOKHandle = AMDialog_GetControlItem ((AMDialog*)self, kOKButton);
  91.     SetDefaultState (self->mOKHandle, true);
  92.     SetDialogDefaultItem (((AMDialog*)self)->mDialog, kOKButton);
  93.     self->mCancelHandle = AMDialog_GetControlItem ((AMDialog*)self, kCancelButton);
  94.     SetDialogCancelItem (((AMDialog*)self)->mDialog, kCancelButton);
  95.     self->mDate2Handle = AMDialog_GetControlItem ((AMDialog*)self, kDate2Field);
  96.     self->mTime2Handle = AMDialog_GetControlItem ((AMDialog*)self, kTime2Field);
  97.     self->mMessage2Handle = AMDialog_GetControlItem ((AMDialog*)self, kMessage2Field);
  98.     self->mDisplayIconHandle = AMDialog_GetControlItem ((AMDialog*)self, kDisplayIconCheck);
  99.     self->mDisplayAlertHandle = AMDialog_GetControlItem ((AMDialog*)self, kDisplayAlertCheck);
  100.     self->mPlaySoundHandle = AMDialog_GetControlItem ((AMDialog*)self, kPlaySoundCheck);
  101.     self->mSoundPopupHandle = AMDialog_GetControlItem ((AMDialog*)self, kSoundPopupPopup);
  102. }
  103.  
  104. //----------
  105. void    Add_ConnectToData (
  106.     Add*        self,
  107.     AMSignaler*        inData)
  108. {
  109.     AMDialog_ConnectToData ((AMDialog*)self, inData);
  110.     self->mData = (DReminder*) inData;
  111.  
  112.     SetClockDateTime (self->mDate2Handle, GetDateAndTime (self->mData));
  113.     SetClockDateTime (self->mTime2Handle, GetDateAndTime (self->mData));
  114.     SetControlTextStr (self->mMessage2Handle, GetMessage (self->mData));
  115.     SetControlValue (self->mDisplayIconHandle, GetShowIcon (self->mData));
  116.     SetControlValue (self->mDisplayAlertHandle, GetShowAlert (self->mData));
  117.     SetControlValue (self->mPlaySoundHandle, GetPlaySound (self->mData));
  118.     SetControlValue (self->mSoundPopupHandle, GetSoundIndex (self->mData));
  119. }
  120.  
  121. //----------
  122. void    Add_DoItem (
  123.     Add*        self,
  124.     SInt16        inItemHit)
  125. {
  126.     switch (inItemHit) {
  127.     case kOKButton:
  128.             AMDialog_SetResult ((AMDialog*)self, true);
  129.         break;
  130.     case kCancelButton:
  131.             AMDialog_SetResult ((AMDialog*)self, false);
  132.         break;
  133.     case kDate2Field:
  134.             SetDateAndTime (self->mData, GetClockDateTime (self->mDate2Handle));
  135.         break;
  136.     case kTime2Field:
  137.             SetDateAndTime (self->mData, GetClockDateTime (self->mTime2Handle));
  138.         break;
  139.     case kMessage2Field:
  140.             SetMessageHandle (self->mData, GetEditTextChars (self->mMessage2Handle));
  141.         break;
  142.     case kDisplayIconCheck:
  143.             SetShowIcon (self->mData, ToggleCheckbox (self->mDisplayIconHandle));
  144.         break;
  145.     case kDisplayAlertCheck:
  146.             SetShowAlert (self->mData, ToggleCheckbox (self->mDisplayAlertHandle));
  147.         break;
  148.     case kPlaySoundCheck:
  149.             SetPlaySound (self->mData, ToggleCheckbox (self->mPlaySoundHandle));
  150.         break;
  151.     case kSoundPopupPopup:
  152.             SetSoundIndex (self->mData, GetControlValue (self->mSoundPopupHandle));
  153.         break;
  154.  
  155.     } // switch
  156. }
  157.  
  158. //----------
  159. void    Add_DataChanged (
  160.     Add*        self,
  161.     long        inDataID)
  162. {
  163.     if (inDataID == idDateAndTime) {
  164.         SetClockDateTime (self->mDate2Handle, GetDateAndTime (self->mData));
  165.     }
  166.     if (inDataID == idDateAndTime) {
  167.         SetClockDateTime (self->mTime2Handle, GetDateAndTime (self->mData));
  168.     }
  169.     if (inDataID == idMessage) {
  170.         SetControlTextStr (self->mMessage2Handle, GetMessage (self->mData));
  171.     }
  172.     if (inDataID == idShowIcon) {
  173.         SetControlValue (self->mDisplayIconHandle, GetShowIcon (self->mData));
  174.     }
  175.     if (inDataID == idShowAlert) {
  176.         SetControlValue (self->mDisplayAlertHandle, GetShowAlert (self->mData));
  177.     }
  178.     if (inDataID == idPlaySound) {
  179.         SetControlValue (self->mPlaySoundHandle, GetPlaySound (self->mData));
  180.     }
  181.     if (inDataID == idSoundIndex) {
  182.         SetControlValue (self->mSoundPopupHandle, GetSoundIndex (self->mData));
  183.     }
  184. }
  185.  
  186. //----------
  187. Boolean        Add_Filter (
  188.     Add*            self,
  189.     EventRecord            *ioEvent,
  190.     DialogItemIndex        *outItemHit)
  191. {
  192.     return AMDialog_Filter ((AMDialog*)self, ioEvent, outItemHit);
  193. }
  194.